<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

<?php include("servor/utils/functions.php"); ?>
<html>
    <head>
        <center><h1>Formulaire d'ajout de machine</h1>
            <script language='javascript'>
                
                function verifIP(){
                    var ip = document.forms['monForm'].elements['ip'].value;
                    var valid = ip.split('.');
                    
                    valid2 = new Array(valid[0], valid[1], valid[2], valid[3]);
                    if(valid2[0] <= 255 && valid2[0] > 0 && valid2[1] <= 255 && valid2[1] > 0 && valid2[2] <= 255 && valid2[2] > 0 && valid2[3] <= 255 && valid2[3] > 0){
                        return(true);
                    }
                    else{ 
                        alert('Adresse IP incorrecte');  
                        return(false);
                    }
                }
                
                function verifRam(){
                    var ram = document.forms['monForm'].elements['ram'].value;
                    
                    if((ram > 0) || (ram === "")){
                        return(true);
                    }
                    else{
                        alert('Veuillez rentrez un nombre positif pour la RAM ou laisser vide');
                        return(false);
                    }
                }
                
                function verifHdd(){
                    var hdd = document.forms['monForm'].elements['hdd'].value;
                    
                    if((hdd > 0) || (hdd === "") ){
                        return(true);
                    }
                    else{
                        alert('Veuillez rentrez un nombre positif pour le HDD ou laisser vide');
                        return(false);
                    }
                }
                
                function verifForm(){
                    if (verifIP() && verifRam() && verifHdd()){
                        return(true);
                    }
                    else{
                        return(false);
                    }
                }
            </script>
    </head>
    <body>
        <form action='data/create/machine.php' method='POST' name='monForm' onSubmit='return verifForm();'>
            <table>
                <tr>
                    <td>Salle : </td>
                    <td> <SELECT name='salle' size='1'>
                              <?php
                                $json = file_get_contents('http://127.0.0.1/projects/Bliss/trunk/Bliss/data/get/salle.php');
                                $data = json_decode($json,true);
                                foreach ($data as $classe){
                                    echo "<option>".$classe["name"]."</option>";            
                                }
                                ?>
                          </SELECT></td>
                </tr>
                <tr>
                    <td>Adresse IP : </td>
                    <td> <input type ='text' name='ip' required="required"/></td>
                </tr>
                <tr>
                    <td>RAM : </td>
                    <td> <input type='text' name='ram'></td>
                    <td><select name='tailleRam' >
                            <option>Mb</option>
                            <option>Gb</option>
                        </select>
                    </td>
                <tr>
                    <td>Disque Dur : </td>
                    <td> <input type='text' name='hdd' /></td>
                    <td><select name='tailleHdd' >
                            <option>Mb</option>
                            <option>Gb</option>
                            <option>Tb</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td> <input type='submit' value='Envoyer' /></td>
                </tr>
            </table>
        </form>
        </center>
    </body>
</html>



